// npm i  作用
// 生产依赖  项目上线
// 开发依赖  我们开发写代码的过程   nodemon

const express = require("express");
const path = require("path");
const cors = require("cors");
const bodyParser = require("body-parser");
const db = require("./db/index");
const app = express();
// 暴露静态文件
app.use(express.static(path.join(__dirname, "public")));
// 使用cors解决跨域问题
app.use(cors());
// 使用bodyParser
app.use(
  bodyParser.urlencoded({
    extended: true
  })
);
// 连接数据库
app.use("/", async (req, res, next) => {
  await db;
  next();
});
// 引入路由器模块
const registerLogin = require("./routes/registerLogin");
const hairProject = require("./routes/hairProject");
const memberLevel = require("./routes/memberLevel");
const employeeInfo = require('./routes/employeeInfo');
// 应用路由
app.use(registerLogin);
app.use(hairProject);
app.use(memberLevel);
app.use(employeeInfo);

app.listen(3000, err => {
  if (!err) console.log("server启动");
  else console.log(err);
});